from apps.common.base.serializers import *
from apps.merchant.sku.models import *


class SkuBaseSerializer(BaseSerializer):
    class Meta:
        model = Sku
        fields = "__all__"


class SkuModelSerializer(BaseSerializer):

    itemModel = serializers.SerializerMethodField()
    def get_itemModel(self, obj):
        try:
            return {'id': obj.item.id, 'name': obj.item.name, 'cateName': obj.item.cate.name if obj.item.cate else '-', 'activityName': obj.item.activity.name if obj.item.activity else '-'}
        except:
            return {}

    class Meta:
        model = Sku
        fields = "__all__"
